带显著性检验的填色图

您所在的位置:网站首页 python地图打点 海外 带显著性检验的填色图

带显著性检验的填色图

2023-09-13 06:41| 来源: 网络整理| 查看: 265

以一个序列和一个场的相关系数为例,绘制带显著性检验的填色图。

对于一个序列 a(T)和一个场 b(T, M, N), T可理解为时间维度,如40年,M,N分别为纬度和经度。其相关系数及对应的P值为:

1234567import numpy as npfrom scipy.stats import pearsonrr = np.zeros((M,N))p = np.zeros((M,N))for i in range(M): for j in range(N): r[i,j], p[i,j] = pearsonr(a, b[:,i,j])

p值小于0.01(0.05)则为通过0.01(0.05)置信度显著性检验的区域,以此类推。

图形绘制:

123456789101112131415161718192021222324252627282930313233import cartopy.crs as ccrsimport cartopy.feature as cfeatureimport matplotlib.pyplot as pltimport cartopy.mpl.ticker as cticker#选择投影proj = ccrs.PlateCarree(central_longitude=245)#创建图形fig = plt.figure(figsize=(12,8))fig_ax1 = fig.add_axes([0.1, 0.1, 0.5, 0.5],projection = proj)#设置边界leftlon, rightlon, lowerlat, upperlat = (130,360,-20,70)img_extent = [leftlon, rightlon, lowerlat, upperlat]fig_ax1.set_extent(img_extent, crs=ccrs.PlateCarree())#绘制海岸线和湖泊等地理特征fig_ax1.add_feature(cfeature.COASTLINE.with_scale('50m')) fig_ax1.add_feature(cfeature.LAKES, alpha=0.5)#设置刻度及刻度标签格式fig_ax1.set_xticks(np.arange(leftlon,rightlon+30,30), crs=ccrs.PlateCarree())fig_ax1.set_yticks(np.arange(lowerlat,upperlat+30,30), crs=ccrs.PlateCarree())lon_formatter = cticker.LongitudeFormatter()lat_formatter = cticker.LatitudeFormatter()fig_ax1.xaxis.set_major_formatter(lon_formatter)fig_ax1.yaxis.set_major_formatter(lat_formatter)#绘制相关系数填色cf1 = fig_ax1.contourf(lon,lat,r, zorder=0, levels =np.arange(-1,1.1,0.1) , extend = 'both',transform=ccrs.PlateCarree(), cmap=plt.cm.RdBu_r)#绘制显著性打点。思路为将0-0.05范围内的区域用点的标记来填充,来表示显著性95%水平。cf2 = fig_ax1.contourf(lon,lat, p, [0,0.05,1] , zorder=1,hatches=['...', None],colors="none", transform=ccrs.PlateCarree())#色标position=fig3.add_axes([0.1, 0.08, 0.35, 0.025])fig3.colorbar(cf1,cax=position,orientation='horizontal',format='%.2f',)#显示plt.show()

输出图形如下:



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3